﻿using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using GeoTracer;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
	[OperationContract]
	public void DoWork()
	{
		// Add your operation implementation here
		return;
	}

    [OperationContract]
    public ICollection<GeoTracer.IPLocation> GetLocations()
    {
        List<ProbeInfo> probes = IPLookup.GetIps();
        List<GeoTracer.IPLocation> list = new List<IPLocation>();

        try
        {
            int cnt = 0;
            foreach (ProbeInfo pi in probes)
            {
                cnt++;
                IPLocation location = IPLookup.DoLookup(pi.IP);
                if (!location.Error)
                {
                    location.Frequency = pi.Frequency;
                    location.Text = string.Format("{0}: {1}", cnt, pi.ClientID);
                    list.Add(location);
                }
            }
        }
        catch (Exception ex)
        {
            int h;
        }
        return list;
    }
	// Add more operations here and mark them with [OperationContract]
}
